<?php
require_once 'Validator.php';

class Controller {
    /**
     * @var Request
     */
    protected $_request;

    /**
     * @var Response
     */
    protected $_response;

    protected $_view;

    protected $_autoRender = true;
    
    protected $_model;
    
    /**
     * @var Validator
     */
    protected $_validator;

    public function __construct($request, $response, $db) {
        $this->_request = $request;
        $this->_response = $response;
        $this->_view = $response->getView();
        $this->_validator = new Validator();
        $controllerName = $this->_request->getParam('controller');
        $modelClass = dashToCamelCase($controllerName, true) . 'Model';
        $modelPath = APPLICATION_PATH.'src/models/'.$modelClass.'.php';
        if ( file_exists($modelPath) ){
            require_once $modelPath;
            $this->_model = new $modelClass($db);
        }
    }

    public function getRequest() {
        return $this->_request;
    }

    public function getResponse() {
        return $this->_response;
    }

    public function autoRender($controller, $action) {
        if ($this->_autoRender) {
            $this->_response->render($controller . '/' . $action);
        }
    }

    // Controller helper function here
}